package com.nebula.core.config;

import com.baomidou.dynamic.datasource.DynamicRoutingDataSource;
import com.nebula.core.client.NebulaSession;
import com.nebula.core.client.NebulaTemplate;
import com.vesoft.nebula.client.graph.net.Session;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.sql.DataSource;

/**
 * @author zhangtao
 */
@Configuration
@ConditionalOnClass({Session.class})
@Slf4j
public class NebulaAutoConfiguration {

    @Bean
    public NebulaSession sessionPool(DynamicRoutingDataSource dataSource) {
        return new NebulaSession(dataSource.getDataSource("nebula"));
    }

    @Bean
    public NebulaTemplate nebulaTemplate(NebulaSession nebulaSession) {
        return new NebulaTemplate(nebulaSession);
    }

}